import {defHttp} from '/@/utils/http/axios';
import {
    LoginParams,
    LoginResultModel,
    GetUserInfoModel,
    RegisterUserParam,
    UserInfoParam, AuthParam, RoleList, ModifyPasswordParam
} from '/@/api/sys/model/userModel';

import {ErrorMessageMode} from '/#/axios';

enum Api {
    Login = '/sys/portal/login',
    Logout = '/sys/logout',
    GetUserInfo = '/sys/user/info',
    UserInfoPublicApi = '/sys/user',
    UserAuthApi = '/sys/user/auth',
    GetPermCode = '/sys/menu/authCode',
    CheckCode = '/verify-code/judge',
    RegisterApi = '/sys/register',
    getRoleListApi = '/sys/role/cds-list',
    ModifyPasswordApi = '/sys/modifyPassword',
}

/**
 * @description: user login api
 */
export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') {
    return defHttp.post<LoginResultModel>(
        {
            url: Api.Login,
            params,
        },
        {
            errorMessageMode: mode,
        },
    );
}

/**
 * @description: getUserInfo
 */
export function getUserInfo() {
    return defHttp.get<GetUserInfoModel>({url: Api.GetUserInfo}, {errorMessageMode: 'none'});
}

export function getPermCode() {
    return defHttp.get<string[]>({url: Api.GetPermCode});
}

export function doLogout() {
    return defHttp.get({url: Api.Logout});
}

export function checkCode(code: string) {
    return defHttp.get({url: Api.CheckCode, params: {verificationCode: code}});
}

export function register(params: RegisterUserParam) {
    return defHttp.post({url: Api.RegisterApi, params});
}

export function updateProfile(params?: UserInfoParam) {
    return defHttp.put({url: Api.UserInfoPublicApi, params});
}

export function userAuth(params?: AuthParam) {
    return defHttp.post({url: Api.UserAuthApi, params});
}

export function getRoleList() {
    return defHttp.get<RoleList>({url: Api.getRoleListApi});
}


export function modifyPassword(params?: ModifyPasswordParam) {
    return defHttp.post<Object>({url: Api.ModifyPasswordApi, params});
}
